package cn.tedu.store.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tedu.store.entity.Product;
import cn.tedu.store.mapper.ProductMapper;
import cn.tedu.store.service.IProductService;
import cn.tedu.store.service.ex.ProductNotFoundException;

/**
 * 热销商品业务层实现类
 * @author DELL
 *
 */
@Service
public class ProductServiceImpl implements IProductService {
		
	@Autowired
	private ProductMapper mapper;

	@Override
	public List<Product> getHotList() {
		List<Product> list = findHotList();
		for (Product product : list) {
			product.setStatus(null);
			product.setCategoryId(null);
			product.setPriority(null);
			product.setCreatedUser(null);
			product.setCreatedTime(null);
			product.setModifiedUser(null);
			product.setModifiedTime(null);
		}
		return list;
	}
	
	
	private List<Product> findHotList(){
		return mapper.findHotList();
	}


	@Override
	public Product getById(Integer pid) {
		 Product whole  = findById(pid);
		 if(whole == null) {
			 throw new ProductNotFoundException("商品信息不存在！");
		 }
		 whole.setCategoryId(null);
		 whole.setStatus(null);
		 whole.setPriority(null);
		 whole.setCreatedTime(null);
		 whole.setCreatedUser(null);
		 whole.setModifiedTime(null);
		 whole.setModifiedUser(null);
		return whole;
	}
	
	private Product findById(Integer pid) {
		
		return mapper.findById(pid);
		
	}
	
}
